package test;

import java.util.Arrays;
import java.util.Comparator;

public class StudentSort {
    public static void main(String[] args) {
        Stu stus[]=new Stu[4];
        stus[0]=new Stu("yao",12);
        stus[1]=new Stu("wang",8);
        stus[2]=new Stu("hu",19);
        stus[3]=new Stu("li",12);
        System.out.println(Arrays.toString(stus));
        Arrays.sort(stus, new Comparator<Stu>() {
            @Override
            public int compare(Stu o1, Stu o2) {
                if(o1.age!=o2.age){
                    return o1.age-o2.age;
                }else{
                    return o1.name.charAt(0)-o2.name.charAt(0);
                }
            }
        });
        System.out.println(Arrays.toString(stus));
    }
}
class Stu{
    String name;
    int age;

    public Stu(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Stu{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
